package com.ebao.tec.entity;

import java.util.HashMap;
import java.util.Map;

import static com.ebao.tec.constant.Code.*;


/**
 * @DESCRIPTION:
 * @Author: WangLt
 * @Date: 2020/9/7
 */
public class MyResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    public MyResult() {
        put(CODE, CODE_SUCCESS);
        put(MSG, MSG_SUCCESS);
    }

    public static MyResult error() {
        return error(CODE_ERROR, UNKNOWN_ERROR);
    }

    public static MyResult error(String msg) {
        return error(CODE_ERROR, msg);
    }

    public static MyResult error(int code, String msg) {
        MyResult r = new MyResult();
        r.put(CODE, code);
        r.put(MSG, msg);
        return r;
    }

    public static MyResult ok() {
        return new MyResult();
    }

    public static MyResult ok(String msg) {
        MyResult r = new MyResult();
        r.put(MSG, msg);
        return r;
    }

    public static MyResult ok(Map<String, Object> data) {
        MyResult r = new MyResult();
        r.putAll(data);
        return r;
    }

    @Override
    public MyResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
